package org.spring.boot.kafka.demo.producer.controller;

import java.util.Date;

import org.spring.boot.kafka.demo.common.entity.Info;
import org.spring.boot.kafka.demo.common.entity.KafkaConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SendController {

	@Autowired
	KafkaTemplate<String, Object> template;
	
	@GetMapping("/send")
	public Info send(@RequestParam(value="msg",defaultValue="hello")String msg) {
		Info info = new Info(1, "2222", new Date(), msg);
		template.send(KafkaConfig.topic, info);
		return info;
	}
}
